package interfaceComUsuario;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JSplitPane;
import javax.swing.JMenu;
import javax.swing.JTabbedPane;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JTextArea;
import javax.swing.JDesktopPane;
import javax.swing.JLabel;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
//Parte que deveria estar no gerenciador (outra classe), mas devido ao prazo fica aqui mesmo
import acessorios.Carta;
import acessorios.Deck;
//fim da gambiarra

public class FrameSistemaRPGOnline {

	private JFrame frmSistema;
	private AboutScreen sobre;
	private FrameFichaDeadlands framefichaDeadlands;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable()
								   {
										public void run()
										{
											try
											{
												FrameSistemaRPGOnline window = new FrameSistemaRPGOnline();
												window.setVisible(true);
											} 
											catch (Exception e)
											{
												e.printStackTrace();
											}
										}
								   }
					           );
	}

	/**
	 * Create the application.
	 */
	public FrameSistemaRPGOnline()
	{
		initialize();
	}
	
	public void setVisible(boolean arg0)
	{
		frmSistema.setVisible(arg0);
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize()
	{
		frmSistema = new JFrame();
		//frmSistema.setIconImage(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemClassLoader().getResource("resources/32.png")));
		frmSistema.setTitle("Plataforma Online Multi-sistema de RPG de Mesa");
		frmSistema.setBounds(100, 0, 1036, 726);
		frmSistema.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmSistema.getContentPane().setLayout(new BorderLayout(0, 0));
		
		JSplitPane splitPane = new JSplitPane();
		splitPane.setResizeWeight(0.75);
		frmSistema.getContentPane().add(splitPane);
		
		JSplitPane splitPane_1 = new JSplitPane();
		splitPane_1.setResizeWeight(0.58);
		splitPane_1.setOrientation(JSplitPane.VERTICAL_SPLIT);
		splitPane.setRightComponent(splitPane_1);
		
		JDesktopPane panel_1 = new JDesktopPane();
		splitPane_1.setLeftComponent(panel_1);
		panel_1.setVisible(true);
		
		JDesktopPane panel_2 = new JDesktopPane();
		splitPane_1.setRightComponent(panel_2);
		
		JSplitPane splitPane_2 = new JSplitPane();
		splitPane_2.setResizeWeight(0.8);
		splitPane_2.setOrientation(JSplitPane.VERTICAL_SPLIT);
		splitPane.setLeftComponent(splitPane_2);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		splitPane_2.setRightComponent(tabbedPane);
		
		JTextArea textAreaChatPublico = new JTextArea();
		tabbedPane.addTab("Chat P\u00FAblico", null, textAreaChatPublico, null);
		
		JTextArea textAreaRolagens = new JTextArea();
		textAreaRolagens.setEditable(false);
		tabbedPane.addTab("Rolagens", null, textAreaRolagens, null);
		
		JPanel panel_3 = new JPanel();
		tabbedPane.addTab("M\u00E3o do Personagem", null, panel_3, null);
		
		JLabel[] lblCarta = new JLabel[12];
		JPanel[] pnlCarta = new JPanel[12];
		Dimension dimension = new Dimension(90, 140);
		Border borderRaised = BorderFactory.createBevelBorder(BevelBorder.RAISED);
		for(int i=0; i<12; i++)
		{
			pnlCarta[i] = new JPanel();
			LabelCarta labelCarta = new LabelCarta("Carta" + (i+1), null, null, pnlCarta[i]);
			lblCarta[i] = labelCarta;
			pnlCarta[i].setPreferredSize(dimension);
			pnlCarta[i].setBorder(borderRaised);
			pnlCarta[i].add(lblCarta[i]);
			panel_3.add(pnlCarta[i]);
		}
		
		//Parte que deveria estar no gerenciador (outra classe), mas devido ao prazo fica aqui mesmo
		boolean comCuringas = true;
		
		Deck baralho = new Deck(comCuringas);
		baralho.embaralhar();
		Carta carta;
		for(int i=0; i<12; i++)
		{
			carta = baralho.puxarCarta();
			LabelCarta labelCarta = (LabelCarta) lblCarta[i];
			labelCarta.setCarta(carta);
		}
		
		//fim da gambiarra
		
		JSplitPane splitPane_3 = new JSplitPane();
		splitPane_3.setOrientation(JSplitPane.VERTICAL_SPLIT);
		splitPane_2.setLeftComponent(splitPane_3);
		
		JMenuBar menuBar = new JMenuBar();
		splitPane_3.setLeftComponent(menuBar);
		
		JMenu mnSistema = new JMenu("Sistema");
		menuBar.add(mnSistema);
		
		ButtonGroup buttonGroupTipoDeSistema = new ButtonGroup();
		
		JCheckBoxMenuItem rdbtnmntmDeadlands = new JCheckBoxMenuItem("Deadlands");
		rdbtnmntmDeadlands.setSelected(true);
		buttonGroupTipoDeSistema.add(rdbtnmntmDeadlands);
		mnSistema.add(rdbtnmntmDeadlands);
		
		JCheckBoxMenuItem rdbtnmntmDd = new JCheckBoxMenuItem("D&D");
		buttonGroupTipoDeSistema.add(rdbtnmntmDd);
		mnSistema.add(rdbtnmntmDd);
		
		JMenuItem menuItem = new JMenuItem("-----------------");
		menuItem.setEnabled(false);
		mnSistema.add(menuItem);
		
		JMenuItem mntmSair = new JMenuItem("Sair");
		mntmSair.addActionListener(new ActionListener()
										{
											public void actionPerformed(ActionEvent evt)
											{
												frmSistema.dispose();
												sobre.dispose();
											}
										}
								  );
		mnSistema.add(mntmSair);
		
		ButtonGroup buttonGroupTipoDeUsuario = new ButtonGroup();
		
		JMenu mnTipo = new JMenu("Tipo");
		menuBar.add(mnTipo);
		
		JCheckBoxMenuItem mntmMestre = new JCheckBoxMenuItem("Mestre");
		mntmMestre.setEnabled(false);
		mnTipo.add(mntmMestre);
		buttonGroupTipoDeUsuario.add(mntmMestre);
		
		JCheckBoxMenuItem mntmJogador = new JCheckBoxMenuItem("Jogador");
		mntmJogador.setSelected(true);
		mntmJogador.setEnabled(false);
		mnTipo.add(mntmJogador);
		buttonGroupTipoDeUsuario.add(mntmJogador);
		
		JMenu mnCampanha = new JMenu("Campanha");
		menuBar.add(mnCampanha);
		
		JMenuItem mntmContinuar = new JMenuItem("Continuar");
		mntmContinuar.setEnabled(false);
		mnCampanha.add(mntmContinuar);
		
		JMenuItem mntmCriarNova = new JMenuItem("Criar Nova");
		mntmCriarNova.setEnabled(false);
		mnCampanha.add(mntmCriarNova);
		
		JMenuItem mntmConectarAServidor = new JMenuItem("Conectar a servidor");
		mnCampanha.add(mntmConectarAServidor);
		
		JMenu mnFichaDePersonagem = new JMenu("Ficha de Personagem");
		menuBar.add(mnFichaDePersonagem);
		
		JMenuItem mntmCarregarExistente = new JMenuItem("Carregar Existente");
		mntmCarregarExistente.setEnabled(false);
		mnFichaDePersonagem.add(mntmCarregarExistente);
		
		JMenuItem mntmPreencherNova = new JMenuItem("Preencher Nova");
		mnFichaDePersonagem.add(mntmPreencherNova);
		
		JMenu mnAjuda = new JMenu("Ajuda");
		menuBar.add(mnAjuda);

		JMenuItem mntmSobre = new JMenuItem("Sobre");
		mntmSobre.addActionListener(new ActionListener()
		                                {
											public void actionPerformed(ActionEvent evt)
											{
												sobre.setLocationRelativeTo(frmSistema);
												sobre.setModal(true);
												sobre.setVisible(true);
											}
		                                }
		                           );
		mnAjuda.add(mntmSobre);
		
		JDesktopPane panel = new JDesktopPane();
		splitPane_3.setRightComponent(panel);
		framefichaDeadlands = new FrameFichaDeadlands(textAreaRolagens);
		framefichaDeadlands.setBounds(10, 11, 928, 590);
		panel.add(framefichaDeadlands);
		framefichaDeadlands.setVisible(true);
		
		sobre = new AboutScreen();
	}

}
